<?php
/**
 * @copyright SYS Company
 * @author : Mr  Nguyễn Hoàng Long
 * @version : 1.0
 * @name : CRUD Class
 * @todo:  Lớp  mở rộng của CModule. Thao tác danh sách, sửa, xóa cơ sở.
*/
class VimuaBanner extends CModule {
	function init() {
	  $cache_banner_name = portal()->id.'_top_banner';
	  if (!($this->top_banner = CSystem::$cachedata->get($cache_banner_name))) {
	    $this->top_banner = CTable('banner')
	       ->fields('src, width, height, link, banner_type')
	       ->select_all(EEqual('region', 'position5'), array('items_per_page'=>1));
	  }
	}

	function draw() {
		if(!session('view_popup') && request('page')!='product_time_gold') {
			$cache_name = 'pop_up_vimua';
			$cache_time = 400;
			if(!($popup = CSystem::$cachedata->get($cache_name))) {
				$popup = CTable('help')->fields('title,content,image')
					->select(EAnd(EEqual('category_id','PopUp'),EEqual('display',1)), array('order by'=>'created_time desc'));
				CSystem::$cachedata->set($cache_name, $popup, $cache_time);
			}
			session('view_popup', 1);
		} else {
			$popup = NULL;
		}
		$user = user();
		CForm($this->path().'/layout.tpl')->parse(
			($user->is_login()?array('logged'=>true)+$user->data:array('logged'=>false))
			+ array(
				'skin'            => portal()->skin(),
				'is_login'        => $user->is_login(),
				'cart_num_items'  => $user->shopping_cart_count(),
				'popup'           => $popup,
				'top_banner'      => $this->top_banner
			)
		);
 	}

 	function on_draw() {
 		return $this->draw();
 	}
}